package main

import (
	"database/sql"
	"fmt"
	"time"

	_ "github.com/godror/godror"
)

var db *sql.DB

//数据库配置
const (
	host        = "10.100.2.69"
	port        = 1521
	user        = "jingying"
	sqlpassword = "jingying"
	dbname      = "spynet10g"
)

func main() {
	// 用户名/密码@IP:端口/实例名
	osqlInfo := fmt.Sprintf("%s/%s@%s:%d/%s", user, sqlpassword, host, port, dbname)
	DB, err := sql.Open("godror", osqlInfo)
	if err != nil {
		panic(err)
	}
	err = DB.Ping()
	if err != nil {
		panic(err)
	}
	db = DB
	defer db.Close()

	//查找
	sqlStatement := "SELECT sysdate FROM dual"
	stmt, err := db.Prepare(sqlStatement)
	defer stmt.Close()
	if err != nil {
		panic(err)
	}
	rows, err := stmt.Query()
	defer rows.Close()
	if err != nil {
		panic(err)
	}
	systdate := time.Time{}
	for rows.Next() {
		rows.Scan(&systdate)
	}

	fmt.Println(systdate)
}
